/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software Foundation,
 *    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package JET.MouseStuff;

import JET.Centers.ControlCenter;
import java.util.ArrayList;

/**
 *
 * @author 057Ry
 */
public class MouseModeSequence
{
    private ArrayList<Task> taskList;
    private int currentTask;
    static final ControlCenter CC = ControlCenter.getInstance();

    public MouseModeSequence() {
        taskList = new ArrayList<Task>();
        currentTask = 0;
    }

    private void executeTask(int n)
    {
        Task task = taskList.get(n);

        CC.GUIC.setMouseTaskLabel(""+taskList.get(currentTask));
        task.execute();

        if ( !task.needKeyConfirmationToProceed() )
            proceed();
        else
            return;
    }
    public void begin()
    {
        if (!taskList.isEmpty())
        {
            currentTask = 0;
            executeTask(currentTask);
        }
    }
    
    public void proceed()
    {
        if (!taskList.isEmpty())
            if (taskList.get(currentTask).canProceed())
            {
                currentTask++;
                if (currentTask==taskList.size())
                    currentTask = 0;

                executeTask(currentTask);
            }
    }

    public void addTask(Task task)
    {
        taskList.add(task);
    }

    public void clear()
    {
        taskList.clear();
    }

    public Task getCurentTask()
    {
        if (!taskList.isEmpty())
            return taskList.get(currentTask);
        else
            return null;
    }

    public boolean isEmpty()
    {
        return taskList.isEmpty();
    }
}